
Shoulder_View = CreateClientConVar( "Shoulder_View", "1", false, true )
fpsmackwoo = CreateClientConVar( "sh_fpdeath", "1", false, true )

function MyCalcView(ply, pos, angles, fov)
local rdoll = LocalPlayer():GetNWEntity("raggy")
if (rdoll != NULL and rdoll != nil) and fpsmackwoo:GetFloat() == 1 then

local ID = rdoll:LookupAttachment("eyes")
local ragviewpos = rdoll:GetAttachment(ID).Pos
local ragviewang = rdoll:GetAttachment(ID).Ang
local view = {}
    view.origin = ragviewpos+(ragviewang:Forward()*2)
    view.angles = ragviewang
    view.fov = fov
	return view
elseif Shoulder_View:GetFloat() == 1 and (rdoll == NULL or rdoll == nil) then
	
	if LocalPlayer().zoomtime == nil then
	LocalPlayer().zoomtime = CurTime()
	LocalPlayer().zoomc = 0
	end
	if LocalPlayer().zoomtime and LocalPlayer().zoomtime < CurTime() then
	LocalPlayer().zoomc = 0 
	else
	LocalPlayer().zoomc = LocalPlayer().zoomtime - CurTime()
	end
	
	if (!LocalPlayer():InVehicle()) then
				local tracedata = {}
				tracedata.start = pos
				tracedata.endpos = pos-(angles:Forward()*90)
				tracedata.filter = ply
				tracedata.mask = MASK_SOLID_BRUSHONLY
			local trace = util.TraceLine(tracedata)
				local tracedataR = {}
				tracedataR.start = pos
				tracedataR.endpos = pos+(angles:Right()*50)
				tracedataR.filter = ply
				tracedataR.mask = MASK_SOLID_BRUSHONLY
			local traceR = util.TraceLine(tracedataR)
			
			
		local view = {}
		view.angles = angles
		view.fov = fov
	if LocalPlayer().KeyRel == false then
		if trace.Hit then
			view.origin = pos-(angles:Forward()*80*trace.Fraction)+(angles:Right()*25*traceR.Fraction)
		else
			view.origin = pos-(angles:Forward()*(80 - (80*LocalPlayer().zoomc)))+(angles:Right()*25*traceR.Fraction) -- the right part isn't quite working
		end

		return view
	else
		if trace.Hit then
			view.origin = pos-(angles:Forward()*40*trace.Fraction)+(angles:Right()*25*traceR.Fraction)
		else
			view.origin = pos-(angles:Forward()*(40 + (80*LocalPlayer().zoomc)))+(angles:Right()*25*traceR.Fraction)
		end

		return view
	end
end
end
end
hook.Add("CalcView", "MyCalcView", MyCalcView)
 
function RedDot(ply)
if Shoulder_View:GetFloat() == 1 then
local t = util.GetPlayerTrace(LocalPlayer())
local tr = util.TraceLine(t)
cam.Start3D(EyePos(), EyeAngles())
		//Draw a laser dot at the end of the beam.
		local Size = (math.random() * 1.35) + 3 
		render.SetMaterial(Material("Sprites/light_glow02_add_noz"))
		render.DrawQuadEasy(tr.HitPos, (EyePos() - tr.HitPos):GetNormal(), Size, Size, Color(0,255,0,255), 0)
		cam.End3D()
end
end
hook.Add("HUDPaint","RedDot",RedDot)
 
hook.Add("ShouldDrawLocalPlayer", "MyHax ShouldDrawLocalPlayer", function(ply)
        if LocalPlayer():InVehicle() or Shoulder_View:GetFloat() != 1 then
		return false
		else
		return true
		end
end)

local function KeyRel( um )
LocalPlayer().KeyRel = um:ReadBool()
LocalPlayer().zoomtime = CurTime() + 0.5
end
usermessage.Hook( "KeyRel", KeyRel )

local function wRag( um )
LocalPlayer().doll =  um:ReadString()
print(LocalPlayer().doll)
end
usermessage.Hook( "wRag", wRag )

	
	
	
	
